/**
 * 
 */
package nl.boektrust.btsoep.shared.model;

import java.io.Serializable;
import java.util.Locale;


import com.google.gwt.i18n.client.CurrencyData;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * @author rao3
 *
 */
public class Price implements Serializable,IsSerializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -9151963412451298834L;
	private int priceAmountInCents;
	private PriceTypeCode priceTypeCode;
	/**
	 * @return the priceAmountInCents
	 */
	public int getPriceAmountInCents() {
		return priceAmountInCents;
	}
	
	/**
	 * @param priceAmountInCents the priceAmountInCents to set
	 */
	public void setPriceAmountInCents(int priceAmountInCents) {
		this.priceAmountInCents = priceAmountInCents;
	}
	/**
	 * @return the priceTypeCode
	 */
	public PriceTypeCode getPriceTypeCode() {
		return priceTypeCode;
	}
	
	
	
	/**
	 * @param priceTypeCode the priceTypeCode to set
	 */
	public void setPriceTypeCode(PriceTypeCode priceTypeCode) {
		this.priceTypeCode = priceTypeCode;
	}
	/**
	 * @param priceAmountInCents
	 * @param priceTypeCode
	 */
	public Price(int priceAmountInCents, PriceTypeCode priceTypeCode) {
		super();
		this.priceAmountInCents = priceAmountInCents;
		this.priceTypeCode = priceTypeCode;
	}
	
	/**
	 * @param priceAmountInCents
	 * @param priceTypeCode
	 */
	public Price(PriceTypeCode priceTypeCode) {
		this (-1, priceTypeCode);
	}
	
	/**
	 * @param priceAmountInCents
	 * @param priceTypeCode
	 */
	public static String toString(int priceAmountInCents)  {

		/* safe to use following code in GWT environment, but 'manual' code works too 
		NumberFormat fmt = NumberFormat.getDecimalFormat();
		NumberFormat.getCurrencyFormat("eur");
	    double value = this.priceAmountInCents/100;
	    String formatted = fmt.format(value);
	    return formatted;
	    */
	  String st = "Prijs onbekend";
	  if (priceAmountInCents >= 0) {
		  st = "EUR " + priceAmountInCents/100 + ",";
		  if ((priceAmountInCents % 100) == 0) {
			  st = st + "-";
		  } else if ((priceAmountInCents % 100) < 10){	
			  st = st + "0" + priceAmountInCents%100;
		  } else {
			  st = st + priceAmountInCents%100;
		  }
	  }
	  return st;
	}
	
	public String toString() {
		return Price.toString(this.priceAmountInCents);
	}
	
	public Price() {
		this (-1, PriceTypeCode.UNDEFINED);
	}

}
